<template>
  <div>
    <div class="header-box">
      <div class="business-img">
        <img src="@/assets/images/home/business/business.png" />
      </div>
      <div class="tab-box">
        <div class="agency" @click="clickActive('agency')" :class="isActive('agency')">我的待办</div>
        <div class="completed" @click="clickActive('completed')" :class="isActive('completed')">我的已办</div>
        <div class="more" @click="goMore">更多></div>
      </div>
    </div>
    <div class="business-content" v-if="flag">
      <div class="business-content-card" v-for="(item, index) in pendingTaskList" :key="index" >
        <div class="business-card-img">
          <img src="@/assets/images/home/business/agency.png" />
        </div>
        <div class="business-card-box">
          <div class="business-word-header">{{ item.processInstanceName }}</div>
          <div class="business-word-bottom">
            <span>发起日期：</span>
            <span>{{ item.processStartTime }}</span>
            <span class="vertical"></span>
            <span>发起人：</span>
            <span>{{ item.processStartUserName }}</span>
            <span class="vertical"></span>
            <span>代办类型：</span>
            <span>{{ item.processDefinitionName }}</span>
          </div>
        </div>
      </div>
    </div>
    <div class="business-content" v-if="!flag">
      <div class="business-content-card" v-for="(item, index) in finishedTaskList" :key="index">
        <div class="business-card-img">
          <img src="@/assets/images/home/business/agency.png" />
        </div>
        <div class="business-card-box">
          <div class="business-word-header">{{ item.processInstanceName }}</div>
          <div class="business-word-bottom">
            <span>发起日期：</span>
            <span>{{ item.processStartTime }}</span>
            <span class="vertical"></span>
            <span>发起人：</span>
            <span>{{ item.processStartUserName }}</span>
            <span class="vertical"></span>
            <span>代办类型：</span>
            <span>{{ item.processDefinitionName }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getAllTaskList,
  getAllFinishedTaskList,
} from '@/api/wel/task';

export default {
  data() {
    return {
      isActiveKey: 'agency',
      pendingTaskList: [], // 待办集合
      finishedTaskList: [], // 已办集合
      flag: true,
    };
  },
  mounted() {
    this.getAllTaskList();
    this.getAllFinishedTaskList();
  },
  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
    },
    clickActive(key) {
      this.isActiveKey = key;
      // console.log(key, 'key');
      if (key === 'agency') {
        this.flag = true;
      } else {
        this.flag = false;
      }
    },
    isActive(val) {
      return val === this.isActiveKey && 'isActive';
    },
    goMore() {
      this.$router.push('/work/todo/index');
    },
    // 待办接口
    getAllTaskList() {
      getAllTaskList({ page: 1, rows: 4 }).then((res) => {
        this.pendingTaskList = res.data.data.records;
      });
    },
    // 已办接口
    getAllFinishedTaskList() {
      getAllFinishedTaskList({ page: 1, rows: 4 }).then((res) => {
        this.finishedTaskList = res.data.data.records;
      });
    },
  },
};
</script>

<style scoped lang="scss">
.demo-tabs > .el-tabs__content {
  padding: 32px;
  color: #6b778c;
  font-size: 32px;
  font-weight: 700;
}
.header-box {
  display: flex;
  width: 100%;
  height: 47px;
  align-items: center;
  padding-left: 20px;
  border-bottom: 1px solid #f2f2f2;
  .tab-box {
    display: flex;
    height: 47px;
    align-items: center;
    margin-left: 8px;
    .more {
      font-size: 14px;
      margin-left: 330px;
      color: #989da3;
    }
    div {
      box-sizing: border-box;
      height: 100%;
      display: flex;
      align-items: center;
      cursor: pointer;
      border-bottom: 2px solid rgba(0, 0, 0, 0);
      &.isActive {
        border-bottom: 2px solid #2e72ef;
        color: #2e72ef;
        font-weight: 700;
      }
    }
    .agency {
      margin-right: 33px;
    }
  }
}
:deep(.el-tabs__item.is-active)  {
  font-weight: 700;
}
.business-content {
  padding: 16px 20px 10px 20px;
  .business-content-card {
    width: 556px;
    height: 64px;
    background: #f9fafb;
    border-radius: 2px;
    margin-bottom: 10px;
    display: flex;
    .business-card-img {
      width: 36px;
      height: 36px;
      padding: 14px 10px;
    }
    .business-card-box {
      width: 100%;
      height: 100%;
      padding: 14px 0;
      .business-word-header {
        font-size: 14px;
        font-weight: 700;
        margin-bottom: 5px;
      }
      .business-word-bottom {
        font-size: 12px;
        color: #9da2a8;
        .vertical {
          display: inline-block;
          width: 14px;
          height: 8px;
          border-right: 1px solid #9da2a8;
          margin-right: 14px;
        }
      }
    }
  }
}
</style>
